package in.muton.edushare.pages.deptpages;

import in.muton.edushare.pages.folder.FolderBasePanel;
import in.muton.edushare.url.URLLoader;
import in.muton.edushare.wicket.models.CayenneModel;

import org.apache.wicket.PageParameters;
import org.apache.wicket.RestartResponseAtInterceptPageException;
import org.apache.wicket.markup.html.basic.Label;

import com.edushare.common.constants.ApplicationConstants;
import com.edushare.common.constants.URLConstants;
import com.edushare.common.dao.FileDirectoriesDAO;
import com.edushare.common.util.StringUtil;
import com.edushare.common.vo.FileDirectories;

public class DeptFolders extends DeptBase {

	public DeptFolders(PageParameters params) {
		super(params);
		int folderId = params.getInt("f",0);
		System.out.println("folderId: "+ folderId);
		FileDirectories fd;
		if(folderId == 0){
			fd =
				new FileDirectoriesDAO(getSessionORMInterface())
						.getOrCreateRootDir(getModel().getObject());
		}else{
			fd = 
				new FileDirectoriesDAO(getSessionORMInterface())
						.getFileDirById(folderId);
		}
		
		if(fd==null){
			throw new RestartResponseAtInterceptPageException(URLLoader.getPageClass(URLConstants.PAGE_NOT_FOUND_PATH));
		}
		
		CayenneModel<FileDirectories> fdModel = new CayenneModel<FileDirectories>(fd);
		String dirName = StringUtil.ellipsis(fd.getDirectoryName(), 25);
		add(new Label("cwd", dirName));
		add(new FolderBasePanel("ffdiv", fdModel, this));
	
	}

	@Override
	protected String getActivePage(PageParameters params) {
		return "folders";
	}

	@Override
	public String getPageTitle() {
		return getLoggedInUser().getCompleteUserName() + " | "
		+ getModel().getObject().getDeptName()
		+ " | Files & folders | "
		+ ApplicationConstants.APPLICATION_NAME;		
		
	}

}
